package level.editor.main;

import java.awt.Event;
import java.awt.event.KeyEvent;

import javax.swing.JComponent;
import javax.swing.KeyStroke;

import level.editor.menu.RedoCommand;
import level.editor.menu.StateNewCommand;
import level.editor.menu.StateOpenCommand;
import level.editor.menu.StateSaveCommand;
import level.editor.menu.UndoCommand;

public class LevelHotkeys
{	
	public static void createHotkeys(LevelView view)
	{
		// Create hotkey actions
		HotkeyAction undo = new HotkeyAction(view, new UndoCommand());
		HotkeyAction redo = new HotkeyAction(view, new RedoCommand());
		HotkeyAction save = new HotkeyAction(view, new StateSaveCommand());
		HotkeyAction newState = new HotkeyAction(view, new StateNewCommand());
		HotkeyAction open = new HotkeyAction(view, new StateOpenCommand());
		
		/*
		 * Currently used hotkeys:
		 * 	Ctrl + N = New Level
		 * 	Ctrl + S = Save Level
		 * 	Ctrl + O = Open Level
		 * 	Ctrl + Z = Undo
		 * 	Ctrl + Y = Redo
		 * 	Ctrl + D = Display Grid
		 * 	Ctrl + F = Display Foreground
		 * 	Ctrl + B = Display Background
		 */

		view.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(
				KeyStroke.getKeyStroke(KeyEvent.VK_Z, Event.CTRL_MASK), "UNDO");
		view.getActionMap().put("UNDO", undo);
		view.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(
				KeyStroke.getKeyStroke(KeyEvent.VK_Y, Event.CTRL_MASK), "REDO");
		view.getActionMap().put("REDO", redo);
		view.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(
				KeyStroke.getKeyStroke(KeyEvent.VK_S, Event.CTRL_MASK), "SAVE");
		view.getActionMap().put("SAVE", save);
		view.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(
				KeyStroke.getKeyStroke(KeyEvent.VK_N, Event.CTRL_MASK), "NEW");
		view.getActionMap().put("NEW", newState);
		view.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(
				KeyStroke.getKeyStroke(KeyEvent.VK_O, Event.CTRL_MASK), "OPEN");
		view.getActionMap().put("OPEN", open);
	}
}
